package leetcode.sword;

import datastruct.tree.TreeNode;

import java.util.ArrayList;
import java.util.LinkedList;

public class Solution32_1 {

    public int[] levelOrder(TreeNode root) {

        ArrayList<Integer> res = new ArrayList<>();
        LinkedList<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        while (!queue.isEmpty()){
            TreeNode cur = queue.poll();
            if(cur==null) continue;
            res.add(cur.val);
            queue.add(cur.left);
            queue.add(cur.right);
        }
        int[] arr = new int[res.size()];
        for (int i = 0; i < res.size(); i++) {
            arr[i] = res.get(i);
        }
        return arr;
    }
}
